Asciidoctor
Open source implementation of AsciiDoc in Ruby
= Document Title
Doc Writer <doc@asciidoc.org>
v1.0, 2013-01-01: Initial version
http://asciidoc.org[AsciiDoc] is a lightweight markup language.
This is the optional preamble (an untitled section body), useful for
writing simple sectionless documents consisting only of a preamble.
NOTE: The abstract, preface, appendix, bibliography, glossary and
index section titles are significant (_specialsections_).
== First section
Document sections start at *level 1* and can nest four levels deep.
* Item 1
* Item 2
[source,ruby]
puts 'Hello, World!'$ binary: git merge fix-village
warning: Cannot merge binary files: quijote.doc (HEAD vs. fix-village)
Auto-merging quijote.doc
CONFLICT (content): Merge conflict in quijote.doc
Automatic merge failed; fix conflicts and then commit the result.
$ binary: git diff master..fix-village
diff --git a/quijote.doc b/quijote.doc
index 4d7a47b..c8a6206 100644
Binary files a/quijote.doc and b/quijote.doc differ==!
Ruby …Maven, Gradlejvm languages (Groovy, Scala)JavaEERuby offers 4441 gems some like TiltRuby is a dynamic, reflective, object-oriented, general-purpose programming language
Wikipedia
Let’s see some examples
require 'asciidoctor'
class MyClass < Parent
attr_accessor :foo
def initialize
@foo = 28
end
def has_more_lines?
end
def process_line line
end
end
instance = MyClass.new
puts instance.foo
instance.foo = 496age = 12 #Fixnum
debt = 123.45 #Float
msg = "Hello World" #String
array = ["a", "b", "c"] #Array
hash = {"a" => 1, "b"=>2} #Hash
hash2 = {:a => 1} #Hash Symbolsmodule Module1
def self.myMethod
puts "hi"
end
def others
end
end
Module1.myMethodJava implementation of Ruby language
Asciidoctor.render_file('mysample.adoc', :in_place => true,
:backend => 'docbook5')Ruby rubyRuntime = JavaEmbedUtils.initialize(new ArrayList());
RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
RubyInteger rfj = evaler.eval(runtime, "1+2");
evaler.eval(runtime, "puts 'Hello World'");//Ruby block.rb
class Block < AbstractBlock
def initialize(parent, context, opts = {})
end
end
//Java
//Load Ruby script file
String scriptBlockClass = load("block.rb");
evaler.eval(runtime, scriptBlockClass);
//Load class
IRubyObject rubyClass = evaler.eval(runtime, "Block");
String context = ...;
Map<Object, Object> ops = ..;
Object[] parameters = new Object[]{ parent, context, ops };
//Parameters as Java types
JavaEmbedUtils.invokeMethod(runtime, rubyClass, "new", parameters, IRubyObject.class);x.something → x.getSomething() x.something = 42 → x.setSomething(42) x.something? → x.isSomething() x.method_name → x.methodName()
//Ruby
@block_extensions = {:block => class}
def find_block_extension name
@block_extensions[name]
end
//Java
String blockName = "block";
this.asciidoctorModule.find_block_extension(
RubySymbol.newSymbol(rubyRuntime, blockName));//Ruby
require 'java'
require 'asciidoctor'
class AsciidoctorModule java_implements Java::AsciidoctorModuleClass
def render_file(content, options = {})
return Asciidoctor.render_file(content, options)
end
def render(content, options = {})
return Asciidoctor.render(content, options)
end
end
//Java
public interface AsciidoctorModuleClass {
Object render(String content, Map<String, Object> options);
Object render_file(String filename, Map<String, Object> options);
}
Object rfj = evaler.eval(runtime, "AsciidoctorModule.new()");
AsciidoctorModuleClass amc = JavaEmbedUtils.rubyToJava(runtime, (org.jruby.runtime.builtin.IRubyObject) rfj, AsciidoctorModuleClass.class);When I see a bird that walks like a duck and swims like a duck and quacks like a duck.
James Whitcomb
A group of classes to modify content.
require 'asciidoctor'
require 'asciidoctor/extensions'
require 'uri-open'
class UriIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
def handles? target
target.start_with?('http://') or target.start_with?('https://')
end
def process reader, target, attributes
content = open(target).readlines
reader.push_include content, target, target, 1, attributes
end
end
Asciidoctor::Extensions.register do |document|
include_processor UriIncludeProcessor.new
endpublic abstract class IncludeProcessor extends Processor {
public IncludeProcessor() {
this(new HashMap<String, Object>());
}
public IncludeProcessor(Map<String, Object> config) {
super(config);
}
public abstract boolean handles(String target);
public abstract void process(PreprocessorReader reader, String target, Map<String, Object> attributes);
}
extensionProcessor.includeProcessor(new IncludeProcessor(new HashMap<String, Object>()) {
//----
}asciidoctor/ ├── bin/ │ └── asciidoctor ├── lib/ │ └── asciidoctor/ │ └── asciidoctor.rb ├── data/ ├── features/ ├── man/ ├── test/ │ └── attributes_test.rb ├── README.adoc ├── Gemfile ├── Rakefile ├── .travis.yml └── asciidoctor.gemspec
<dependency>
<groupId>rubygems</groupId>
<artifactId>asciidoctor</artifactId>
<version>${asciidoctor.version}</version>
<type>gem</type>
<scope>provided</scope>
</dependency>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>1.0.0-rc4</version>
<configuration>
<jrubyVersion>${jruby.version}</jrubyVersion>
<gemHome>${project.build.directory}/classes</gemHome>
<gemPath>${project.build.directory}/classes</gemPath>
</configuration>
<!-- Executions configuration -->
</plugin>wget -O asciidoctor-master.zip https://github.com/asciidoctor/asciidoctor/archive/master.zip
unzip asciidoctor-master.zip
cp install-asciidoctor-gem.pom asciidoctor-master/pom.xml
cd asciidoctor-master
ASCIIDOCTOR_VERSION=`grep 'VERSION' ./lib/asciidoctor/version.rb | sed "s/.*'\(.*\)'.*/\1/"`
sed -i "s;<version></version>;<version>$ASCIIDOCTOR_VERSION</version>;" pom.xml
mvn install
cd ..
rm -rf asciidoctor-master*
mvn test -Dasciidoctor.version=$ASCIIDOCTOR_VERSION
<!-- install-asciidoctor-gem.pom -->
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
<extensions>true</extensions>
</plugin>